package utils;

import linkList.IntersectionNode.ListNode;

public class linkListUtil {
    public static class ListNode {
        public int val;
        public ListNode next;

        ListNode() {
        }

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static class Node {
        public int val;
        public Node next;
        public Node random;

        public Node(int val) {
            this.val = val;
            this.next = null;
            this.random = null;
        }
    }

    public static ListNode createLinkedList(int[] values) {
        if (values == null || values.length == 0) {
            return null;
        }

        // 创建头节点
        ListNode head = new ListNode(values[0]);
        ListNode current = head;

        // 依次创建后续节点
        for (int i = 1; i < values.length; i++) {
            current.next = new ListNode(values[i]);
            current = current.next;
        }

        return head;
    }
    public static Node createLinkedListByNode(int[] values) {
        if (values == null || values.length == 0) {
            return null;
        }

        // 创建头节点
        Node head = new Node(values[0]);
        Node current = head;

        // 依次创建后续节点
        for (int i = 1; i < values.length; i++) {
            current.next = new Node(values[i]);
            current.random=current.next;
            current = current.next;

        }

        return head;
    }
}
